package com.example.rwq_test.webrtc.doubao;

import org.springframework.web.socket.WebSocketSession;

public class UserSession {
    private Process process;
    private Process videoProcess;
    private Process audioProcess;
    private int rtpPort;
    private int audioPort;
    private int videoPort;

    private WebSocketSession session; // 【新增】保存 WebSocketSession 引用

    // --- Getters and Setters ---
    public WebSocketSession getSession() { return session; } // 【新增】
    public void setSession(WebSocketSession session) { this.session = session; } // 【新增】

    public void setProcess(Process p) { this.process = p; }
    public Process getProcess() { return process; }

    public void setVideoProcess(Process p) { this.videoProcess = p; }
    public Process getVideoProcess() { return videoProcess; }

    public void setAudioProcess(Process p) { this.audioProcess = p; }
    public Process getAudioProcess() { return audioProcess; }

    public void setRtpPort(int port) { this.rtpPort = port; }
    public int getRtpPort() { return rtpPort; }

    public void setAudioPort(int port) { this.audioPort = port; }
    public int getAudioPort() { return audioPort; }

    public void setVideoPort(int port) { this.videoPort = port; }
    public int getVideoPort() { return videoPort; }

    public void release() {
        if (videoProcess != null) {
            videoProcess.destroyForcibly();
            try {
                videoProcess.waitFor();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
        if (audioProcess != null) {
            audioProcess.destroyForcibly();
            try {
                audioProcess.waitFor();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
        if (process != null) {
            process.destroyForcibly();
            try {
                process.waitFor();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
    }
}